
from ..models.meta import DBSession as Session
from ..models.models import *

def get_table_options(table, valueproperty, textproperty, value=''):
    optiontext=''
    exec(
    """
results = Session.query(%s).all()
optiontuples = set([(r.%s, r.%s) for r in results])


for optiontuple in optiontuples:
    if optiontuple[0] == %s:
        optiontext = optiontext + '<option value="%%s" selected>%%s</option>' %% optiontuple
    else:
        optiontext = optiontext + '<option value="%%s">%%s</option>' %% optiontuple
    """ % (table, valueproperty, textproperty, value or "''")
    )
    return optiontext

